package core;

import java.util.HashMap;
import java.util.Random;

public class Data {
	private HashMap<Character, CharCount> _stat;
	
	private static Data _self;

	private byte[][] s;
	private byte[][] m;
	
	public static Data getInstance() {
		if (_self == null) {
			_self = new Data();
		}
		return _self;
	}
	
	private Data() {
		createC36();
	};
	
	private void createC36() {
		int max = 50;
		s = new byte[6][max];
		m = new byte[6][27];
		for (int i = 0; i < max; i++) {
			s[0][i] = 0;
			s[1][i] = 0;
			s[2][i] = 0;
			s[3][i] = 0;
			s[4][i] = 0;
			s[5][i] = 0;
		}
		for (int i = 0; i < 27; i++) {
			m[0][i] = 0;
			m[1][i] = 0;
			m[2][i] = 0;
			m[3][i] = 0;
			m[4][i] = 0;
			m[5][i] = 0;
		}
		
		byte[] sizes = new byte[6];
		sizes[0] = 17;
		sizes[1] = 19;
		sizes[2] = 21;
		sizes[3] = 23;
		sizes[4] = 25;
		sizes[5] = 26;
		
		for (int i = 0; i < sizes.length; i++) {
			createRandomS(i,sizes[i],max);
		}
		
		for (int i = 0; i < 27; i++) {
			createRandomMcolumn(i);
		}
//		for (int i = 0; i < max; i++) {
//			System.out.print(i + "\t");
//		}
//		System.out.println();
//		for (int i = 0; i < sizes.length; i++) { 
//			for (int j = 0; j < max; j++) {
//				System.out.print(s[i][j] + "\t");
//			}
//			System.out.println();
//		}
		
	}

	private void createRandomMcolumn(int i) {
		Random r = new Random();
		int count = 0;
		for (int j = 0; j < 6; j++) {
			if (r.nextBoolean()) {
				m[j][i] = 1;
				count++;
			}
			if (count == 2) {
				return;
			}
		}
	}

	private void createRandomS(int index, byte vectorLength, int max) {
		Random r = new Random();
		for (int i = 0; i < max; i++) {
			if (i < vectorLength) {
				s[index][i] = (byte)r.nextInt(2);
			} else {
				s[index][i] = s[index][i % vectorLength];
			}
		}
	}
	
	public byte[][] getsMatrix() {
		return s;
	}
	public byte[][] getmMatrix() {
		return m;
	}

	public HashMap<Character, CharCount> getStatistic() {
		return _stat;
	}
	
	public void setStatistic(HashMap<Character, CharCount> stat) {
		_stat = stat;
	}
	
	
	
}
